<template>
  <div id="message">
     <div class="detail-content">
        <h1>{{detailContent.title}}</h1>
        <div class="h2-desc">
          <span>{{detailContent.add_time}}</span>
        </div>
        <p class="text-content" v-html="detailContent.content"></p>
        <div class="img-item" v-for="(img,index) in detailContent.images" :key="index" >
          <img :src="img" alt="i业主"  :preview="index" preview-text=""/>
        </div>
      </div>
  </div>
</template>

<script>
import { Toast, Dialog } from "mand-mobile";
import https from "@/https";
import config from "@/config";
export default {
  components: {
    [Dialog.name]: Dialog,
  },
  name: "message",
  data() {
    return {
      yid: null,
      detailContent: {}, //详情内容
    };
  },
  methods: {
    // 显示消息内容
    getDetail(index) {
       Toast.loading('加载中...')
      let yid = this.yid;
      let params = {
        yid,
      };
      https
        .fetchPost(config.getNoticeDetails, params)
        .then(res => {
           Toast.hide()
          if (res.data.code == 1) {
            let content = res.data.data;
            content.add_time = this.dataFormat(content.add_time * 1000, 1);
            if(content.images && content.images.length != 0){
              let arr = [];
              content.images.forEach(item => {
                if(item != ""){
                  if(item.indexOf('sqyzdh.com') == -1 ){
                    let str = "https://mz.sqyzdh.com" + item;
                    arr.push(str);
                  }else {
                    arr.push(item);
                  }
                }
              });
              content.images = arr;
              this.$previewRefresh();
            }
            this.detailContent = content;
          } else {
            Toast.failed(res.data.msg);
          }
        })
        .catch(err => {
           Toast.hide()
          console.log(err);
        });
    },
    // 时间戳转换
    dataFormat(num, type) {
      var dd = new Date(num);
      var y = dd.getFullYear();
      var m = dd.getMonth() + 1;
      var d = dd.getDate();
      var h = dd.getHours();
      var i = dd.getMinutes();
      var s = dd.getSeconds();
      m = m < 10 ? "0" + m : m;
      d = d < 10 ? "0" + d : d;
      h = h < 10 ? "0" + h : h;
      i = i < 10 ? "0" + i : i;
      s = s < 10 ? "0" + s : s;
      if (type == 1) {
        return y + "-" + m + "-" + d + " " + h + ":" + i + ":" + s;
      } else {
        return y + "-" + m + "-" + d + " " + h + ":" + i;
      }
    },
  },
  created() {
    this.yid = this.$route.query.yid;
    this.getDetail();
  }
};
</script>

<style  lang="scss" scoped>
$themeColor: #444444;
$themeGold: #d7b987;
.md-notice-bar {
  z-index: 1;
}
button {
  z-index: 1;
}
.pswp {
  z-index: 99999;
}
#message {
  .message-list {
    height: 100vh;
    padding: 0 40px;
    .item {
      position: relative;
      border-bottom: 1px solid #f2f2f2;
      .tip {
        position: absolute;
        right: 30px;
        top: 30px;
        width: 18px;
        height: 18px;
        border-radius: 50%;
        background: rgb(236, 62, 62);
      }
      .time {
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 24px;
        height: 60px;
        color: #999;
      }
      .desc {
        font-size: 26px;
        color: #666;
        line-height: 44px;
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        /*! autoprefixer: ignore next */
        -webkit-box-orient: vertical;
      }
    }
  }
  .empty-list {
    padding-top: 100px;
    font-size: 30px;
    color: #666;
    text-align: center;
  }
  .bscroll-container {
    min-height: 100%;
  }
  .top-tip {
    position: absolute;
    top: -40px;
    left: 0;
    z-index: 1;
    width: 100%;
    height: 40px;
    line-height: 40px;
    font-size: 28px;
    text-align: center;
    color: #ccc;
  }
  .bottom-tip {
    width: 100%;
    height: 35px;
    line-height: 35px;
    text-align: center;
    color: #999;
    font-size: 28px;
    position: absolute;
    bottom: -45px;
    left: 0;
  }
  .detail-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 30px;
    h1 {
      font-size: 40px;
      font-weight: 600;
      padding-top: 40px;
      line-height: 54px;
      margin-bottom: 40px;
    }
    .h2-desc {
      display: flex;
      align-items: center;
      width: 600px;
      justify-content: center;
      font-size: 26px;
      color: #999;
      margin-bottom: 30px;
    }
    .person-num {
      display: flex;
      width: 100%;
      font-size: 26px;
      color: #666;
      line-height: 40px;
    }
    .text-content {
      width: 100%;
      margin-top: 30px;
      color: #444;
      font-size: 30px;
      line-height: 40px;
      margin-bottom: 40px;
    }
    .img-item {
            box-shadow: 0 0 4px 1px #f2f2f2;

      width: 600px;
      border-radius: 10px;
      overflow: hidden;
      margin-bottom: 30px;
      img {
        display: block;
        width: 600px;
      }
    }
  }
}
</style>
